
<%@page import="web.vungsi"%>
<%@page import="kyakya.Post"%>
<%@page import="kyakya.User"%>
<%@page import="kyakya.manager.DBManager"%>
<%@page import="java.io.File"%>



<%!
   
    
    public static String getExtension(String file) {
        int dotIndex = file.lastIndexOf(".");
        String extension = file.substring(dotIndex + 1, file.length());
        return extension;
    }

    public static String getFileName(String file) {

        int dotIndex = file.lastIndexOf(".");
        int fileSeparatorIndex = file.lastIndexOf(File.separator);
        String fileName = file.substring(fileSeparatorIndex + 1,
                dotIndex);
        return fileName;

    }

    public static String getContent(int userID, int postID) {
        StringBuilder sb = new StringBuilder();
        try {
            User user = DBManager.getUserByID(userID);
            Post post = DBManager.getPost(postID);

            
            
            String content = vungsi.ambilKonten(post.getContent());
            
            
            User author = DBManager.getUserByID(post.getAuthorID());

            content.replace("/watch?v=", "/v/");
            sb.append("<h2><a class='content_title' href='content.jsp?pid=" + postID + "' >" + post.getTitle() + "</a></h2><br/>");
            sb.append("<div class='content_tag'>" + post.getTags() + "</div>");
            sb.append("<div class='content_author'><a href='profile.jsp?pid=" + author.getId() + "'> by " + author.getUsername() + "</a></div>");
            sb.append("<div class='content_date'> created in " + post.getCreateTime() + "</div>");
            sb.append("<div class='content_number'>Like " + post.getLikeCount() + "</div>");
            sb.append("<div class='content_number'>Disike " + post.getDislikeCount() + " </div>");
            sb.append("<div class='content_number'>Commented by " + post.getCommentCount() + " people </div>");            
            sb.append(content + "<br/>");
            if (userID != 0) {
                sb.append("<input type='button' value='Like' OnClick='gaEngga(" + postID
                        + ", " + userID + ")' />"
                        + "<input type='button' value='Dislike' OnClick='Engga(" + postID + ", " + userID+ ")' />");
            }


            // nampilin title, date, author
            // jumlah komentar, jumlah lik dislike, button
            // kontent, 


        } catch (Exception e) {
            e.printStackTrace();
        }


        return sb.toString();
    }

%>

